<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template name="replace">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="contains($string,'&#10;')">
        <xsl:value-of select="substring-before($string,'&#10;')"/>
        <br/>
        <xsl:call-template name="replace">
          <xsl:with-param name="string"
			  select="substring-after($string,'&#10;')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <xsl:template match="/project/schema/table">
    <html>
      <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
	<title>Table&#160;<xsl:value-of select="@name"/></title>
	<link rel="stylesheet" type="text/css" href="../../stylesheet.css"></link>
      </head>
      <body>
	<table bgcolor="#eeeeff" cellspacing="0" cellpadding="1" border="0" width="100%" summary="">
	  <tr>
	    <td>
	      <table cellspacing="3" cellpadding="0" border="0" summary="">
		<tr align="center" valign="top">
		  <td>
		    <a href="../../summary.html">
		      <font class="NavBarFont">
			<b>Overview</b>
		      </font>
		    </a>
		  </td>
		</tr>
	      </table>
	    </td>
	  </tr>
	</table>

	<h2>
	  Table&#160;<xsl:value-of select="@name"/>
	</h2>
	<xsl:call-template name="replace">
          <xsl:with-param name="string" select="@comment"/>
    	</xsl:call-template>
	<br></br>
	<table cellspacing="0" cellpadding="3" border="1" width="100%" summary="">
	  <tr class="TableHeadingColor">
	    <th>Name</th>
	    <th>Type</th>
	    <th>Not Null</th>
	    <th>Default</th>
	    <th>Remarks</th>
	  </tr>
	  <xsl:for-each select="column">
	    <tr class="TableRowColor">
	      <td width="15%">				
		<xsl:if test="@name = ''">&#160;</xsl:if>
		<b><xsl:if test="@name != ''"><xsl:value-of select="@name"/></xsl:if></b>
	      </td>
	      <td width="10%">				
		<xsl:if test="@dataType = ''">&#160;</xsl:if>
		<xsl:if test="@dataType != ''"><xsl:value-of select="@dataType"/></xsl:if>
	      </td>
	      <td width="5%" align="center">				
		<xsl:if test="@isNotNull = ''">&#160;</xsl:if>
		<xsl:if test="@isNotNull = '0'">N</xsl:if>
		<xsl:if test="@isNotNull = '1'">Y</xsl:if>
	      </td>
	      <td width="5%">	
		<xsl:if test="@defaultValue = ''">&#160;</xsl:if>
		<xsl:if test="@defaultValue != ''"><xsl:value-of select="@defaultValue"/></xsl:if>
	      </td>
	      <td width="40%">	
		<xsl:if test="@comment = ''">
			<xsl:if test="@autoIncrement = '1'">AUTO INCREMENT</xsl:if>
			<xsl:if test="@autoIncrement != '1'">&#160;</xsl:if>
		</xsl:if>
		<xsl:if test="@comment != ''">
		<xsl:if test="@autoIncrement = '1'">AUTO INCREMENT<br/></xsl:if>
		  <xsl:call-template name="replace">
        	    <xsl:with-param name="string" select="@comment"/>
    		  </xsl:call-template>
		</xsl:if>
	      </td>
	    </tr>
	  </xsl:for-each>
	</table>
	<p></p>
	<h3>Indices</h3>

	<table cellspacing="0" cellpadding="3" border="1" width="75%" summary="">
	  <tr class="TableHeadingColor">
	    <th>Name</th>
	    <th>Fields</th>
	    <th>Type</th>
	    <th>Remarks</th>
	  </tr>
	  <xsl:for-each select="index">
	    <tr class="TableRowColor">
	      <td width="15%">				
		<xsl:if test="@name = ''">&#160;</xsl:if>
		<b><xsl:if test="@name != ''"><xsl:value-of select="@name"/></xsl:if></b>
	      </td>
	      <td width="15%">
		<xsl:for-each select="field">				
		  <xsl:if test="(.) = ''">&#160;</xsl:if>
		  <xsl:if test="(.) != ''"><xsl:value-of select="(.)"/></xsl:if>
		</xsl:for-each>	
	      </td>
	      <td width="15%">				
		<xsl:if test="@indexType = ''">&#160;</xsl:if>
		<xsl:if test="@indexType != ''"><xsl:value-of select="@indexType"/></xsl:if>
	      </td>
	      <td width="25%">
		<xsl:for-each select="comment">				
		  <xsl:if test="(.) = ''">&#160;</xsl:if>
		  <xsl:if test="(.) != ''">			
		    <xsl:call-template name="replace">
        	      <xsl:with-param name="string" select="(.)"/>
    		    </xsl:call-template>
		  </xsl:if>
		</xsl:for-each>	
	      </td>
	    </tr>
	  </xsl:for-each>
	</table>
	<xsl:if test="foreignKey">
	  <p></p>
	  <h3>Foreign Keys</h3>
	  <table cellspacing="0" cellpadding="3" border="1" width="75%" summary="">
	    <tr class="TableHeadingColor">
	      <th>Name</th>
	      <th>Fields</th>
	      <th>Referenced Fields</th>
	      <th>Remarks</th>
	    </tr>
	    <xsl:for-each select="foreignKey">
	      <tr class="TableRowColor">
		<td width="15%">				
		  <xsl:if test="@name = ''">&#160;</xsl:if>
		  <b><xsl:if test="@name != ''"><xsl:value-of select="@name"/></xsl:if></b>
		</td>
		<td width="15%">
		  <xsl:for-each select="field">				
		    <xsl:if test="(.) = ''">&#160;</xsl:if>
		    <xsl:if test="(.) != ''"><xsl:value-of select="(.)"/></xsl:if>
		  </xsl:for-each>	
		</td>
		<td width="15%">
		  <xsl:for-each select="refField">				
		    <xsl:if test="(.) = ''">&#160;</xsl:if>
		    <xsl:if test="(.) != ''">
		      <xsl:element name="a">
			<xsl:attribute name="href">
			  <xsl:value-of select="@refTable"/>.html
			</xsl:attribute>
			<xsl:text><xsl:value-of select="(.)"/></xsl:text>
		      </xsl:element>
		    </xsl:if>
		  </xsl:for-each>	
		</td>
		<td width="25%">
		  <xsl:for-each select="comment">				
		    <xsl:if test="(.) = ''">&#160;</xsl:if>
		    <xsl:if test="(.) != ''">			
		      <xsl:call-template name="replace">
        		<xsl:with-param name="string" select="(.)"/>
    		      </xsl:call-template>
		    </xsl:if>
		  </xsl:for-each>	
		</td>
	      </tr>
	    </xsl:for-each>
	  </table>
	</xsl:if>
	<p></p>
	<div id="footer">
	  <i><small>Last change date :&#160;<xsl:value-of select="@lastChangeDate"/></small></i>
	  <hr></hr>
	  <center>
	    <a href="http://Jingsy.gaixie.org">Jingsy Powered</a>&#160;&#160;
	    <a href="http://www.gnu.org/copyleft/fdl.html">GPL licensed</a>&#160;&#160;
	  </center>
	</div>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>
